import QtQuick
import QtQuick.Controls //qt风格
//import Qt.labs.platform //native 风格menu

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    MouseArea{
        anchors.fill: parent
        acceptedButtons: Qt.RightButton
        onClicked: {
            menu.x = mouseX
            menu.y = mouseY
            menu.open()
        }
    }

    Menu{
        id: menu
        padding: 6
        background: Rectangle{
            radius: 6
            color: "#20000000"
            implicitWidth: 200 //使用width不会显示
            implicitHeight: 10
        }
        delegate: MenuItem{
            id: menuItem
            implicitWidth: 200
            implicitHeight: 30
            rightPadding: 6

            //icon text shortcut arrow
            arrow: Canvas {
                implicitWidth: 10
                implicitHeight: 10
                x: parent.width - width - menuItem.rightPadding
                y: (menuItem.implicitHeight - implicitHeight) / 2
                visible: menuItem.subMenu
                onPaint: {
                    var ctx = getContext("2d")
                    ctx.fillStyle = menuItem.highlighted ? "#ffffff" : "#c0000000"
                    ctx.moveTo(0, 0)
                    ctx.lineTo(0, height)
                    ctx.lineTo(width, height / 2)
                    ctx.closePath()
                    ctx.fill()
                }
            }
            contentItem:  Text{text: menuItem.text}
            background: Rectangle {
                implicitHeight: 50
                opacity: enabled ? 1 : 0.3
                color: menuItem.highlighted ? "#20000000" : "transparent"
                radius: 4
            }
        }

        Action { text: qsTr("复制") }
        Action { text: qsTr("粘贴") }

        Item{
            height: 6
            MenuSeparator {anchors.centerIn: parent}
        }

        Menu{
            title: qsTr("更多打开方式")
            Action { text: qsTr("从xxx打开") }
        }
    }
}
